<template>
  <rx-layout>
    <div slot="center" style>
      <rx-fit>
        <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
          <div class="table-operator">
            <rx-button alias="formTransConfigAdd" :butn-icon="'plus'" :butn-type="'primary'" :show-no-right="true" @click="add">{{$ti18('rxList.newBtn','新建')}}</rx-button>
            <a-dropdown v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
              <a-button style="margin-left: 8px"> {{$ti18('rxList.moreBtn','更多')}} <a-icon type="down" /> </a-button>
              <a-menu slot="overlay">
                <a-menu-item key="1" v-if="editEnable && selectedRowKeys.length > 0" alias="formTransConfigEdit" :butn-icon="'edit'"
                             :butn-type="'primary'" :show-no-right="false" @click="editOne"><a-icon type="edit"  />{{$ti18('rxList.editBtn','编辑')}}</a-menu-item>
                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0" alias="formTransConfigDelete" :butn-icon="'delete'" :butn-type="'danger'"
                             :show-no-right="false" @click="delByIds(selectedRowKeys)"><a-icon type="delete" />{{$ti18('rxList.delBtn','删除')}}</a-menu-item>
              </a-menu>
            </a-dropdown>
          </div>
          <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
        </div>
        <div slot="searchbar" btnalign="right"  v-if="fitSearch" @search="search" @cancel="cancel" @close="close">
          <a-form layout="vertical">
                <a-form-item :label="i18n('form.name','名称')">
                    <a-input :placeholder="i18n('form.name','请输入名称','input')" v-model="queryParam.Q_NAME__S_LK" allowClear/>
                </a-form-item>
                <a-form-item :label="i18n('form.status','状态')">
                    <a-select v-model="queryParam.Q_STATUS__I_EQ" allowClear>
                        <a-select-option v-for="item of statusMap" :value="item.value">{{item.label}}</a-select-option>
                    </a-select>
                </a-form-item>
                <a-form-item :label="i18n('form.transType','转换类型')">
                    <a-select v-model="queryParam.Q_TRANS_TYPE__S_LK" allowClear>
                        <a-select-option v-for="item of tranType" :value="item.value">{{item.label}}</a-select-option>
                    </a-select>
                </a-form-item>
          </a-form>
        </div>
        <rx-grid
                ref="table"
                :allowRowSelect="true"
                :multiSelect="true"
                :columns="columns"
                :defaultPageSize="10"
                url="/api-form/form/core/formTransConfig/query"
                :queryParam="queryParam"
                data-field="result.data"
                :pageSizeOptions="['10','30','40']"
                id-field="id"
                @selectChange="onSelectChange"
        >
          <span slot="status" slot-scope="{ text, record }">
                <a-tag :color="statusRender[text].color">
                  <span>{{ statusRender[text].text }}</span>
                </a-tag>
          </span>
            <span slot="transType" slot-scope="{ text, record }">
                  {{ tranTypeRender[text] }}
          </span>
          <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                    <span  @click="edit(record)">{{$ti18('rxList.editBtn','编辑')}}</span>
                    <span  @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
          </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>

<script>
  import FormTransConfigApi from '@/api/form/core/formTransConfig'
  import FormTransConfigEdit from './FormTransConfigEdit'
  import {BaseList,RxFit,RxGrid } from "@lowcode/jpaas-common-lib";
  export default {
    name: 'FormTransConfigList',
    mixins: [BaseList],
    components: {
      RxFit
    },
    data() {
      return {
        columns: [
          {
            title: this.$ti18('rxList.index','序号'),
            type: 'indexColumn',
            width: 100,
            dataIndex: 'serial',
            scopedSlots: {customRender: 'serial'}
          },
          {title: this.i18n('form.name','名称'), dataIndex: 'name', width: 100},
          {title: this.i18n('form.sourceBodefName','源业务模型名称'), dataIndex: 'sourceBodefName', width: 100},
          {title: this.i18n('form.targetSolutionName','目标表单方案名称'), dataIndex: 'targetSolutionName', width: 100},
          {title: this.i18n('form.status','状态'), dataIndex: 'status', width: 100,  scopedSlots: {customRender: 'status'}},
          {title: this.i18n('form.transType','转换类型'), dataIndex: 'transType', width: 100,scopedSlots: {customRender: 'transType'}},
          {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
        ],
        component:FormTransConfigEdit,
        comment: this.i18n("list.comment","转换配置表"),
        /*widthHeight:['1000px','800px'],*/
        fitSearch:false,
        statusRender: {
            "1": {color: 'green', text: this.$comi18('rxDialog.statusYse', '启用')},
            "0": {color: 'red', text: this.$comi18('rxDialog.statusNo', '禁用')}
        },
        tranTypeRender:{
            'onetoone':this.i18n('tranType.onetoone','一对一'),
            'manytoone':this.i18n('tranType.manytoone','多对一'),
            "rule":this.i18n('tranType.rule','根据分组合并规则生成')
        },
        statusMap: [
            {label:this.$comi18('rxDialog.statusYse', '启用'),value:1},
            {label:this.$comi18('rxDialog.statusNo', '禁用'),value:0}
        ],
        tranType: [
            {label: this.i18n('tranType.onetoone','一对一'), value: 'onetoone'},
            {label: this.i18n('tranType.manytoone','多对一'), value: 'manytoone'},
            {label: this.i18n('tranType.rule','根据分组合并规则生成'), value: 'rule'}
        ],
      }
    },
    created(){
        this.queryParam["Q_APP_ID__S_EQ"]=this.$route.query.appId
    },
    methods:{
      i18n(name,text,key){
          return this.$ti18(name,text,"formTransConfig",key);
      },
      delById(ids){
        return FormTransConfigApi.del({ ids: ids.join(',') });
      },
      getListByParams(parameter){
        return FormTransConfigApi.query(parameter)
      },
    }
  }
</script>
<style scoped>
  .table-operator {
    padding:4px;
  }
  .table-operator button {
    margin:2px;
  }
</style>

